

import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


public class RawDataHandler 
{
	public static Data ParseData(String file) throws IOException
	{
		BufferedReader br = new BufferedReader(new FileReader(file));
		Data warehouseData = new Data();
		
	    try 
	    {	    
	    	warehouseData = new Data();
	        String line = br.readLine();
	        String[] s = line.split(" ");
	        
	        int nbWarehouse = Integer.parseInt(s[0]);
	        int nbCustomer = Integer.parseInt(s[1]);
	        
	        String[] curLine;
	              
	        
	        Warehouse[] warehouses = new Warehouse[nbWarehouse];   
	        for(int i = 0; i < nbWarehouse; i++)
	        {
	        	line = br.readLine();
	        	s = line.split(" ");
	        	warehouses[i] = new Warehouse(i, Integer.parseInt(s[0]), Double.parseDouble(s[1]));
	        }
	        
	        

	        Customer[] customers = new Customer[nbCustomer];
	        for(int i = 0; i < nbCustomer; i++)
	        {
	        	
	        	line = br.readLine();
	        	s = line.split(" ");
	        	int demand = Integer.parseInt(s[0]);
	        	
	        	line = br.readLine();
	        	s = line.split(" ");
	        	double[] cost = new double[nbWarehouse];
	        	for(int j = 0; j < nbWarehouse; j++)
	        	{
	        		cost[j] = Double.parseDouble(s[j]);
	        	}
	        	
	        	customers[i] = new Customer(i, demand, cost);
	        }
	        
	        warehouseData.warehouses = warehouses;
	        warehouseData.customers = customers;
	       
	    } 
	    finally 
	    {
	        br.close();
	    }

	    return warehouseData;
	}
	
	private static double CalculateCost(Data warehouseData)
	{
		double cost = 0;
		for(int i = 0; i < warehouseData.customers.length; i++)
		{
			cost += warehouseData.customers[i].cost[warehouseData.customers[i].warehouseId];
		}
		
		for(int i = 0; i < warehouseData.warehouses.length; i++)
		{
			cost += warehouseData.warehouses[i].setupCost * (warehouseData.warehouses[i].isOpen ? 1 : 0);
		}
		return cost;
	}
	
	public static void OutputSolution(Data warehouseData)
	{
		double totalCost = CalculateCost(warehouseData);
		String path = "";
		for(int i = 0; i < warehouseData.customers.length; i++)
		{
			path += warehouseData.customers[i].warehouseId + " ";
		}
		
		System.out.println(totalCost + " 0");
		System.out.println(path);
	}
}
